package com.le.tester.book.concurrentchallenge.cancelclose;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * createTime：2025-04-07 10:30
 * description：
 */
public class ReaderThread extends Thread {

    private final Socket socket;
    private final InputStream in;
    private static final int BUF = 1024;

    public ReaderThread(Socket socket) throws IOException {
        this.socket = socket;
        this.in = socket.getInputStream();
    }

    public void interrupt() {
        try {
            socket.close();
        } catch (IOException ignore) {

        } finally {
            super.interrupt();
        }
    }

    public void run() {
        try {
            byte[] bytes = new byte[BUF];
            while (true) {
                int count = in.read(bytes);
                if (count < 0) {
                    break;
                } else if (count > 0) {
                    //processBuffer();
                }

            }

        } catch (IOException e) {

        }
    }
}
